package com.tang.portal.controller.admin.sys;

import com.tang.framework.core.controller.BaseController;
import com.tang.framework.core.domain.HttpResult;

import com.tang.common.model.req.ReqId;
import com.tang.portal.facade.admin.sys.SysMenuFacade;
import com.tang.service.admin.model.req.ReqSysMenu;
import com.tang.service.admin.model.req.ReqSysMenuAdd;
import com.tang.service.admin.model.res.ResRoute;
import com.tang.service.admin.model.res.ResSysMenuTableItem;
import com.tang.service.admin.model.res.ResSysMenuDetail;
import com.tang.common.model.req.ReqIds;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import lombok.SneakyThrows;
import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author tang jun liang
 * @Date ${gen.dateTime}
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController extends BaseController {

    @Resource
    private SysMenuFacade sysMenuFacade;


    @Operation(summary = "删除菜单表")
    @PostMapping("/remove")
//    @PreAuthorize("@as.hasPermission('sys:menu:remove')")
    public HttpResult<String> remove(@RequestBody ReqIds ids) {
        return sysMenuFacade.remove(ids, getCurrLoginUser());
    }

    @Operation(summary = "菜单表详情")
    @PostMapping("/detail")
    public HttpResult<ResSysMenuDetail> detail(@RequestBody ReqId id) {
        return sysMenuFacade.detail(id, getCurrLoginUser());
    }

    @Operation(summary = "菜单表详情")
    @PostMapping("/list")
//    @PreAuthorize("@as.hasPermission('sys:menu:list')")
    public HttpResult<List<ResSysMenuTableItem>> list(@RequestBody ReqSysMenu reqSysMenu) {
        return sysMenuFacade.list(reqSysMenu, getCurrLoginUser());
    }

    @Operation(summary = "按钮权限列表")
    @PostMapping("/button/authorize/list")
//    @PreAuthorize("@as.hasPermission('sys:menu:list')")
    public HttpResult<List<ResSysMenuTableItem>> buttonAuthorizeList(@RequestBody ReqIds ids) {
        return sysMenuFacade.buttonAuthorizeList(ids, getCurrLoginUser());
    }



    @Operation(summary = "新增菜单表")
    @PostMapping("/add")
    public HttpResult<String> add(@RequestBody ReqSysMenuAdd sysMenuAdd){
        return sysMenuFacade.add(sysMenuAdd);
    }

    @Operation(summary = "编辑菜单表")
    @PostMapping("/update")
    public HttpResult<String> update(@RequestBody ReqSysMenuAdd sysMenuAdd){
        return sysMenuFacade.update(sysMenuAdd);
    }


    @Operation(summary = "导出excel-菜单表")
    @PostMapping("/export")
    public void export(@RequestBody ReqIds ids){
        sysMenuFacade.export(ids, httpServletResponse);
    }

    @Operation(summary = "导出excel-模版")
    @PostMapping("/export/template")
    public void exportTemplate(){
        sysMenuFacade.exportTemplate(httpServletResponse);
    }

    @SneakyThrows
    @Operation(summary = "导入excel-菜单表")
    @PostMapping("/import")
    public HttpResult<String> importExcel(MultipartFile file){
        return sysMenuFacade.importExcel(file);
    }


    @Operation(summary = "获取菜单路由信息")
    @PostMapping("/getRoute")
    public HttpResult<List<ResRoute>> getRoute(){
        return sysMenuFacade.getRoute(getCurrLoginUser());
    }


}
